package com.eight.travel.controller;


import com.eight.travel.pojo.FoodMp;
import com.eight.travel.pojo.Foodrestaurant;
import com.eight.travel.service.AdminFoodService;
import com.eight.travel.utils.BaseResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@Api(value = "管理员功能")
@RestController
@RequestMapping("/adminfood")
public class AdminFoodController {
    @Resource
    AdminFoodService adminFoodService;
//查询food
@ApiOperation(value = "查询所有food")
    @GetMapping("/findAll")
    public BaseResp findAll(){
        List<FoodMp> list = adminFoodService.list();
        list.forEach(System.out::println);
        if (list.size()!=0)
            return new BaseResp().SUCCESS("查询成功",list,null);
        return new BaseResp().FAIL("查询失败");
    }
    //
    @ApiOperation(value = "删除food",notes = "传入当前食物id")
    @DeleteMapping("/delete/{fid}")
    public BaseResp deleteById(@PathVariable int fid){
        boolean b = adminFoodService.removeById(fid);
        if (b)
            return new BaseResp().SUCCESS("删除成功",null,null);
        return new BaseResp().FAIL("删除失败");

    }
    @ApiOperation(value = "添加food")
    @PostMapping("addfood")
    public BaseResp addFood(@RequestBody FoodMp foodMp){
        boolean save = adminFoodService.save(foodMp);
        if (save)
            return new BaseResp().SUCCESS("添加成功",null,null);
        return new BaseResp().FAIL("添加失败");
    }
    @ApiOperation(value = "修改食物信息",notes = "传入修改的值")
    @PostMapping("update")
    public BaseResp updateFood(@RequestBody FoodMp foodMp){
        /*QueryWrapper<FoodMp> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("fid",Fid);*/
        Boolean b = adminFoodService.updateById(foodMp);
        if (b)
            return new BaseResp().SUCCESS("修改成功",null,null);
        return new BaseResp().FAIL("修改失败");
    }
//餐厅crud、
@ApiOperation(value = "查询所有餐厅")
    @GetMapping("/findrest")
    public BaseResp findrest(){
        BaseResp allrest = adminFoodService.findAllrest();
        return allrest;
    }
    @ApiOperation(value = "删除餐厅信息",notes = "传入id")
    @DeleteMapping("/deleterest/{faid}")
    public BaseResp deleterest(@PathVariable int faid){
        BaseResp baseResp = adminFoodService.deleterestById(faid);
        return baseResp;
    }
    @ApiOperation(value = "修改餐厅信息",notes = "传入修改的值")
    @PostMapping("/updaterest")
    public BaseResp updaterest(@RequestBody Foodrestaurant foodrestaurant){
        BaseResp updaterest = adminFoodService.updaterest(foodrestaurant);
        return updaterest;
    }
    @ApiOperation(value = "增加餐厅",notes = "传入增加的foodrestaurant")
    @PostMapping("/addrest")
    public BaseResp addrest(@RequestBody Foodrestaurant foodrestaurant){
        BaseResp addrest = adminFoodService.addrest(foodrestaurant);
        return addrest;
    }
    @ApiOperation(value = "修改餐厅营业状态",notes = "传入status，1营业，0不营业")
    @PostMapping("/updatestatus/{faid}")
    public BaseResp updateststus(@PathVariable int faid){
        return adminFoodService.updateststus(faid);
    }
}
